/**
 * 飞机类
 * Author:  suyuyi
 * Date:    2017.4.16
 */

module.exports = cc.Class({
    extends: cc.Component,

    properties:{
     nickname : {
            default : null,
            type    : cc.Label,
            tooltip : "名字"
        },
       avatar : {
            default : null,
            type    : cc.Node,
            tooltip : "皮肤"
        },
        arrow : {
            default : null,
            type    : cc.Node,
            tooltip : "移动方向提示图标"
        },
        _speed: 5
    },
    setSpeed(value){
        this._speed = value;
    },
    setName(nick){
        this.nickname.getComponent(cc.Label).string = nick;
    },
    setAvatar(avatar){
        this.avatar = cc.find(avatar,this.node);
        //.getComponent(cc.Sprite);

    },
    setArrow(arrow){

    },
    // use this for initialization
    onLoad: function () {
        this.node.active = true;
        this.nickname = cc.find("lab_name",this.node);
        this.nickname.getComponent(cc.Label).string = "suyuyi";
        this.hero = this.node;
        this.avatar = cc.find("spr_avatar",this.node);
        this.arrow = cc.find("spr_avatar/spr_arrow",this.node);
       
    },
    heroMove(angle){
        this.hero.x += Math.cos( angle ) * this._speed;  
        this.hero.y += Math.sin( angle ) * this._speed;
    },
    heroMove8(angle){
         if(angle > 67.5 && angle < 112.5)  
        {  
            this.hero.y += this._speed;  
        }  
        else if(angle > -112.5 && angle < -67.5)  
        {  
            this.hero.y -= this._speed;  
        }  
        else if(angle < -157.5 && angle > -180 || angle > 157.5 && angle < 180)  
        {  
            this.hero.x -= this._speed;  
        }  
        else if(angle < 0 && angle > -22.5 || angle > 0 && angle < 22.5)  
        {  
            this.hero.x += this._speed;  
        }  
        else if(angle > 112.5 && angle < 157.5)  
        {  
            this.hero.x -= this._speed / 1.414;  
            this.hero.y += this._speed / 1.414;  
        }  
        else if(angle > 22.5 && angle < 67.5)  
        {  
            this.hero.x += this._speed / 1.414;  
            this.hero.y += this._speed / 1.414;  
        }  
        else if(angle > -157.5 && angle < -112.5)  
        {  
            this.hero.x -= this._speed / 1.414;  
            this.hero.y -= this._speed / 1.414;  
        }  
        else if(angle > -67.5 && angle < -22.5)  
        {  
            this.hero.x += this._speed / 1.414;  
            this.hero.y -= this._speed / 1.414;  
        }  
    },
     getPlaneRotation: function(){
        return cc.find("spr_avatar", this.node).rotation;
    }
});
